#include <stdio.h>
#define N 4
#define B 9
int main()
{
	int v[N]={2,3,4,5},w[N]={2,3,4,5},dp[N][B]={0},i,j;
	for(i=1;i<N;i++)
	{
		for(j=1;j<B;j++)
		{
			if(j<w[i])
			{
				dp[i][j]=dp[i-1][j];
			}
			else
			{
				if(dp[i-1][j-w[i]]+v[i]>dp[i-1][j])
				{
					dp[i][j]=dp[i-1][j-w[i]]+v[i];
				}
				else
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	printf("%d",dp[N-1][B-1]);
	return 0;
}
